package cn.yhp.mybatis.type;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.Date;

/**
 * @author yhp
 * @date 2023/12/16
 */
public class DateTypeHandler extends BaseTypeHandler<Date>{
    @Override
    protected void setNonNullParameter(PreparedStatement ps, int i, Date parameter, JdbcType jdbcType) throws SQLException {
        ps.setTimestamp(i,new Timestamp(parameter.getTime()));
    }

    @Override
    protected Date getNullableResult(ResultSet rs, String columnName) throws SQLException {
        Timestamp timestamp = rs.getTimestamp(columnName);
        if (timestamp!=null){
            return new Date(timestamp.getTime());
        }
        return null;
    }
}
